package com.uniledger.exchange.wallet;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import io.reactivex.Flowable;
import io.reactivex.Single;

import static android.arch.persistence.room.OnConflictStrategy.REPLACE;

@Dao
public interface WalletKeyDao {

    @Query("SELECT * FROM WalletKey WHERE uid=(:uid)")
    Flowable<WalletKey> loadKey(long uid);

    @Insert(onConflict = REPLACE)
    long insert(WalletKey key);

    @Update(onConflict = REPLACE)
    int update(WalletKey key);

    @Query("UPDATE WalletKey SET isBackup=(:isBackup) WHERE id=(:id) AND uid=(:uid)")
    int update(long uid, long id, boolean isBackup);

    @Query("DELETE FROM WalletKey")
    void deleteKey();

}
